package com.practice.string;

import java.util.HashSet;

public class FindPanlindromes {
	public HashSet<String> find(String input) {
		HashSet<String> set = new HashSet<String>();
		char[] c = input.toCharArray();
		int N = input.length();
		
		for (int i=1; i<N-1; i++) {
			int j = 1;
			while (i>=j && i+j<N && c[i-j]==c[i+j]) {
				set.add(input.substring(i-j, i+j+1));
				j++;
			}
		}
		
		for (int i=0; i<N-1; i++) {
			int j = 1;
			while (i>=j-1 && i+j<N && c[i-j+1]==c[i+j]) {
				set.add(input.substring(i-j+1, i+j+1));
				j++;
			}
		}
		
		return set;
	}
}
